package com.eam.asset.file.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.eam.asset.file.vo.AssetPlace.AssetPlaceAddVo;
import com.eam.asset.file.vo.AssetPlace.AssetPlacePutVo;
import com.eam.asset.file.vo.AssetPlace.AssetPlaceQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.eam.common.annotation.Log;
import com.eam.common.core.controller.BaseController;
import com.eam.common.core.domain.AjaxResult;
import com.eam.common.enums.BusinessType;
import com.eam.asset.file.domain.AssetPlace;
import com.eam.asset.file.service.IAssetPlaceService;
import com.eam.common.utils.poi.ExcelUtil;
import com.eam.common.core.page.TableDataInfo;

/**
 * 场地资产档案Controller
 *
 * @author tzf
 * @date 2023-10-31
 */
@RestController
@RequestMapping("/asset/place")
@Validated
@Api(tags = "场地资产控制器")
public class AssetPlaceController extends BaseController {
    private final IAssetPlaceService assetPlaceService;

    //构造器注入
    @Autowired
    public AssetPlaceController(IAssetPlaceService assetPlaceService) {
        this.assetPlaceService = assetPlaceService;
    }

    /**
     * 查询场地资产档案列表
     */
    @PreAuthorize("@ss.hasPermi('asset:place:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询资产列表")
    public TableDataInfo list(AssetPlaceQueryVo assetPlace) {
        startPage();
        List<AssetPlace> list = assetPlaceService.selectAssetPlaceList(assetPlace);
        return getDataTable(list);
    }

    /**
     * 导出场地资产档案列表
     */
    @PreAuthorize("@ss.hasPermi('asset:place:export')")
    @Log(title = "场地资产档案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出Excel")
    public void export(HttpServletResponse response, AssetPlaceQueryVo assetPlace) {
        List<AssetPlace> list = assetPlaceService.selectAssetPlaceList(assetPlace);
        ExcelUtil<AssetPlace> util = new ExcelUtil<AssetPlace>(AssetPlace.class);
        util.exportExcel(response, list, "场地资产档案数据");
    }

    /**
     * 获取场地资产档案详细信息
     */
    @PreAuthorize("@ss.hasPermi('asset:place:query')")
    @GetMapping(value = "/{placeId}")
    @ApiOperation(value = "查询场地资产")
    public AjaxResult getInfo(@PathVariable("placeId") String placeId) {
        return success(assetPlaceService.selectAssetPlaceByPlaceId(placeId));
    }

    /**
     * 新增场地资产档案
     */
    @PreAuthorize("@ss.hasPermi('asset:place:add')")
    @Log(title = "场地资产档案", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "添加场地资产")
    public AjaxResult add(@RequestBody AssetPlaceAddVo assetPlace) {
        return toAjax(assetPlaceService.insertAssetPlace(assetPlace));
    }

    /**
     * 修改场地资产档案
     */
    @PreAuthorize("@ss.hasPermi('asset:place:edit')")
    @Log(title = "场地资产档案", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改场地资产")
    public AjaxResult edit(@Validated @RequestBody AssetPlacePutVo assetPlace) {
        return toAjax(assetPlaceService.updateAssetPlace(assetPlace));
    }

    /**
     * 删除场地资产档案
     */
    @PreAuthorize("@ss.hasPermi('asset:place:remove')")
    @Log(title = "场地资产档案", businessType = BusinessType.DELETE)
    @DeleteMapping("/{placeIds}")
    @ApiOperation(value = "删除场地资产")
    public AjaxResult remove(@PathVariable String[] placeIds) {
        return toAjax(assetPlaceService.deleteAssetPlaceByPlaceIds(placeIds));
    }
}
